package com.ysd.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.ysd.gulimall.order.config.AlipayTemplate;
import com.ysd.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;

@Controller
public class PayWebController {
    @Autowired
    AlipayTemplate alipayTemplate;
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn")String orderSn, @RequestParam("payAmount")BigDecimal payAmount) throws AlipayApiException {

        PayVo payVo = new PayVo();
        payVo.setBody("lazy data don't want to display!");
        payVo.setOut_trade_no(orderSn);
        payVo.setSubject("商品");
        payAmount.setScale(2,BigDecimal.ROUND_UP);
        payVo.setTotal_amount(payAmount.toString());
        String pay = alipayTemplate.pay(payVo);
        return pay;
    }
}
